package org.inasnet.audio;

import java.io.*;
import java.util.concurrent.LinkedBlockingQueue;

import org.inasnet.BytesPackQueue;
import org.inasnet.*;
import org.inasnet.user.Session;
import org.inasnet.util.Util;

public class SessionSoundBuffer 
{
	public SessionSoundBuffer( Session session )
	{
		mInputSound  = new InputSound();
		mOutputSound = new OutputSound();
		
		mSession = session;
	}
	
	/**
	 * Writes inputs to buffer
	 *
	 */
	public class InputSound// extends SoundStream
	{
		public BytesPack poolPack()
		{
			return mAudioPacks.poll();
		}
		
		public void addAudioBytes( byte [] audioBytes, int numBytes )
	    {
			mAudioPacks.add( audioBytes, numBytes );
	    }
		
		public void addAudioBytes( byte [] data ) 
		{
			mAudioPacks.add( data, data.length );
		}
		
		BytesPackQueue mAudioPacks = new BytesPackQueue();
	}
	
	public class OutputSound
	{
		public void addAudioBytes( byte [] audioBytes, int numBytes )
	    {
			if( audioBytes == null )
				return;
			
			if( audioBytes.length == 0 || numBytes == 0 )
				return;
			
			mSession.sendAudioBytes( audioBytes, numBytes );
	    }
	}
	
	public InputSound getInputSound() 
	{
		return mInputSound;
	}
	
	public OutputSound getOutputSound() 
	{
		return mOutputSound;
	}
	
	InputSound mInputSound;
	
	OutputSound mOutputSound;
	
	ByteArrayOutputStream mOut;
	
	ByteArrayInputStream mIn;

	Session mSession;
}
